package com.xdf.xzymanagementsystem.util;

import com.xdf.xzymanagementsystem.entity.SysUser;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

@Service
public class SessionUtils {
    @Autowired
    HttpServletRequest request; //通过注解获取一个request
    @Autowired
    private ShiroUtils shiroUtils;
    public void setUser(){
        SysUser currentUser = shiroUtils.getCurrentUser();
        if(currentUser == null) return;
        HttpSession session = request.getSession();
        session.setAttribute(SystemConfig.SYSTEM_USER,currentUser);
    }

    public SysUser getUser(){
        HttpSession session = request.getSession();
        return (SysUser)session.getAttribute(SystemConfig.SYSTEM_USER);
    }
}
